﻿using System;
using System.Net;
using System.Windows;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MiruPublic;

namespace MangaKurosagi
{
    public class Stories
    {
        public bool Update = false;
        public string UrlImage
        {
            get;
            set;
        }
        public string Title
        {
            get;
            set;
        }
        public string Description
        {
            get;
            set;
        }
        public string Url
        {
            get;
            set;
        }
        public static Stories Convert(ItemDetails item)
        {
            return new Stories() { Title = item.Title, Url = item.Url, UrlImage = item.UrlImage, Description = item.Description };
        }
        public static ItemDetails Convert(Stories item)
        {
            return new ItemDetails { Title = item.Title, Description = item.Description, Url = item.Url, UrlImage = item.UrlImage };
        }
        public event EventHandler<GetListChapCompletedEventArgs> GetListChapCompleted;

        protected virtual void GetListCompleted(GetListChapCompletedEventArgs e)
        {
            EventHandler<GetListChapCompletedEventArgs> handler = GetListChapCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public void GetListChap()
        {
            LeadChap client = new LeadChap();

            client.DownLoadURL(Url);

            client.ListUpdateSucess += (s, args) =>
            {
                Title = Utils.GetStringBetweenText(args.content, "<h1>", "</h1>");

                UrlImage = Utils.GetStringBetweenText(args.content, "src=\"", "\"");

                Description = Utils.strip_tags(Utils.GetStringBetweenText(args.content, "<span class=\"mota\">", "</span>").Trim());

                GetListChapCompletedEventArgs arg = new GetListChapCompletedEventArgs();
                arg.listResult = args.listResult;
                arg.info = this;
                GetListCompleted(arg);
            };
        }
    }
    public class GetListChapCompletedEventArgs : EventArgs
    {
        public List<ItemChap> listResult = new List<ItemChap>();
        public Stories info = new Stories();
    }
}
